# APPENDIX TABLES
# Authors: Mark Kayser & Kasia Nalewajko
# Date created: Feb 9, 2023
# Replicated: Nov 19, 2025

rm(list = ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("xtable")) install.packages("xtable")
if (!require("stargazer")) install.packages("stargazer")
if (!require("estimatr")) install.packages("estimatr")

# LOAD DATA ----

setwd("set/path/to/folder")

load(file = "./01 data/02 generated data/study1/01results_fullsample_clean.Rda")
results1 <- results %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1)))

load(file = "./01 data/02 generated data/study2/02results_fullsample_clean.Rda")
results2 <- results %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3)

# PREP VARS ----

results1 <- results1 %>% 
  mutate(PiS_or_PO_and_party_id = PiS_or_PO,
         PiS_or_PO_and_party_id = ifelse(is.na(PiS_or_PO_and_party_id) & party_id == 3, 1, PiS_or_PO_and_party_id),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 1, "PiS", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 2, "PO", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 999, NA, as.character(PiS_or_PO_and_party_id)))

results2 <- results2 %>% 
  mutate(PiS_or_PO_and_party_id = PiS_or_PO,
         PiS_or_PO_and_party_id = ifelse(is.na(PiS_or_PO_and_party_id) & party_id == 3, 1, PiS_or_PO_and_party_id),
         PiS_or_PO_and_party_id = ifelse(is.na(PiS_or_PO_and_party_id) & party_id == 15, 2, PiS_or_PO_and_party_id),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 1, "PiS", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 2, "PO", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 999, NA, as.character(PiS_or_PO_and_party_id)))


# MAKE TABLE A1 ----

temp <- results1 %>% 
  dplyr::select(outcome, female, yob, locality_size, education, LR, conservative, GSparty_id)
temp <- as.data.frame(temp)

stargazer(temp, type = "latex", title="Descriptive statistics of the main variables used in the analyses (Study 1)", min.max=TRUE, mean.sd = TRUE, 
          nobs = TRUE, median = TRUE, digits=3, align=T,
          covariate.labels = c("Outcome", "Female", "Year of birth", "Locality size", "Education level", "Left-right ID",  "Liberal-Conservative ID", "Graham-Svolik party ID (Partisanship)")
          )

# MAKE TABLE A2 ----

temp <- results2 %>% 
  dplyr::select(outcome, female, yob, locality_size, education, LR, conservative, GSparty_id)
temp <- as.data.frame(temp)

stargazer(temp, type = "latex", title="Descriptive statistics of the main variables used in the analyses (Study 2)", min.max=TRUE, mean.sd = TRUE, 
          nobs = TRUE, median = TRUE, digits=3, align=T,
          covariate.labels = c("Outcome", "Female", "Year of birth", "Locality size", "Education level", "Left-right ID",  "Liberal-Conservative ID", "Graham-Svolik party ID (Partisanship)")
)

# MAKE TABLE A3 ----

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1)))

# subset data to make sure I compare each treatment against the control
POtreatment <- temp %>% 
  filter(exp_condition %in% c("POwins", "control")) %>% 
  mutate(treated = ifelse(exp_condition == "POwins", 1, 0))

# generate vector of covariates for the test
covariates <- c("gender", "yob", "locality_size", "voivodeship", "education",
                "popis", "conservative", "LR",
                "GSparty_id", "survey_date", "experiment_first"
)

# create empty container
cov_checkPO <- data.frame(covariate = character(), coefficient_PO = numeric(), p_value_PO = numeric(), stringsAsFactors = FALSE)

# loop through each covariate
for (i in covariates) {
  # Construct the formula
  formula <- as.formula(paste("treated ~", i))
  
  # Fit the linear regression model
  model <- lm(formula, data = POtreatment)
  
  # Extract coefficient and p-value
  coefficient <- coef(model)[2]  # Extract the coefficient for the covariate
  p_value <- summary(model)$coefficients[2, 4]  # Extract the p-value for the covariate
  
  # Add results to the data frame
  cov_checkPO <- rbind(cov_checkPO, data.frame(covariate = i,
                                               coefficient_PO = coefficient,
                                               p_value_PO = p_value))
  print(i)
}

# subset data to make sure I compare each treatment against the control
PiStreatment <- temp %>% 
  filter(exp_condition %in% c("PiSwins", "control")) %>% 
  mutate(treated = ifelse(exp_condition == "PiSwins", 1, 0))

# generate vector of covariates for the test
covariates <- c("gender", "yob", "locality_size", "voivodeship", "education",
                "popis", "conservative", "LR",
                "GSparty_id", "survey_date", "experiment_first"
)

# create empty container
cov_checkPiS <- data.frame(covariate = character(), coefficient_PiS = numeric(), p_value_PiS = numeric(), stringsAsFactors = FALSE)

# loop through each covariate
for (i in covariates) {
  # Construct the formula
  formula <- as.formula(paste("treated ~", i))
  
  # Fit the linear regression model
  model <- lm(formula, data = PiStreatment)
  
  # Extract coefficient and p-value
  coefficient <- coef(model)[2]  # Extract the coefficient for the covariate
  p_value <- summary(model)$coefficients[2, 4]  # Extract the p-value for the covariate
  
  # Add results to the data frame
  cov_checkPiS <- rbind(cov_checkPiS, data.frame(covariate = i,
                                                 coefficient_PiS = coefficient,
                                                 p_value_PiS = p_value))
  print(i)
}

cov_check_exp2 <- left_join(cov_checkPO, cov_checkPiS, by = "covariate")

cov_check_exp2 <- xtable(cov_check_exp2)
digits(cov_check_exp2) <- 3
print(cov_check_exp2, include.rownames = FALSE)

# MAKE TABLE A4 ----

# keep only those respondents who formed part of the final sample
temp <- results2 %>% 
  filter(outcome != 99) %>% 
  filter(manipulation_check == 3)

# subset data to make sure I compare each treatment against the control
POtreatment <- temp %>% 
  filter(exp_condition %in% c("ChinaPO", "China")) %>% 
  mutate(treated = ifelse(exp_condition == "ChinaPO", 1, 0))

# generate vector of covariates for the test
covariates <- c("gender", "yob", "locality_size", "voivodeship", "education",
                "popis", "conservative", "LR",
                "GSparty_id", "int_security_most_important",
                "survey_date", "demographic_qs_first")

# create empty container
cov_checkPO <- data.frame(covariate = character(), coefficient_PO = numeric(), p_value_PO = numeric(), stringsAsFactors = FALSE)

# loop through each covariate
for (i in covariates) {
  # formula
  formula <- as.formula(paste("treated ~", i))
  
  # model
  model <- lm(formula, data = POtreatment)
  
  # extract
  coefficient <- coef(model)[2]  # Extract the coefficient for the covariate
  p_value <- summary(model)$coefficients[2, 4]  # Extract the p-value for the covariate
  
  # add to df
  cov_checkPO <- rbind(cov_checkPO, data.frame(covariate = i,
                                               coefficient_PO = coefficient,
                                               p_value_PO = p_value))
  print(i)
}

PiStreatment <- temp %>% 
  filter(exp_condition %in% c("ChinaPiS", "China")) %>% 
  mutate(treated = ifelse(exp_condition == "ChinaPiS", 1, 0))

# create empty container
cov_checkPiS <- data.frame(covariate = character(), coefficient_PiS = numeric(), p_value_PiS = numeric(), stringsAsFactors = FALSE)

# loop through each covariate
for (i in covariates) {
  # formula
  formula <- as.formula(paste("treated ~", i))
  
  # model
  model <- lm(formula, data = PiStreatment)
  
  # extract
  coefficient <- coef(model)[2]  # Extract the coefficient for the covariate
  p_value <- summary(model)$coefficients[2, 4]  # Extract the p-value for the covariate
  
  # create df
  cov_checkPiS <- rbind(cov_checkPiS, data.frame(covariate = i,
                                                 coefficient_PiS = coefficient,
                                                 p_value_PiS = p_value))
  print(i)
}

cov_check_exp1 <- left_join(cov_checkPO, cov_checkPiS, by = "covariate")


cov_check_exp1 <- xtable(cov_check_exp1)

digits(cov_check_exp1) <- 3

print(cov_check_exp1, include.rownames = FALSE)

# MAKE TABLE A5 ----

load(file = "./01 data/02 generated data/study1/01results_fullsample_clean.Rda")

temp <- results %>% 
  mutate(attrited = ifelse(is.na(manipulation_check1), 0, 1)) %>% 
  mutate(attrited = ifelse(manipulation_check1 == 3, 0, attrited)) %>% 
  mutate(attrited = ifelse(outcome == 99, 1, attrited))

differential_attrition_check <- glm(attrited ~ as.factor(manipulation_check1) + exp_condition, 
                                    data = temp, 
                                    family = binomial)

options("modelsummary_format_numeric_latex" = "plain")
modelsummary(list("DV: attrited [0;1]" = differential_attrition_check),
             stars = c('*' = .1, '**' = .05, '***' = .01),
             output = "latex",
             title = "Differential attrition check (Study 1)"
)

# MAKE TABLE A6 ----

load(file = "./01 data/02 generated data/study2/02results_fullsample_clean.Rda")

temp <- results %>% 
  mutate(attrited = ifelse(outcome == 99 | manipulation_check != 3, 1, 0)) %>% 
  mutate(no_outcome_answer = ifelse(outcome == 99, 1, 0))

differential_attrition_check <- glm(attrited ~ as.factor(manipulation_check) + exp_condition, 
                                    data = temp, 
                                    family = binomial)

options("modelsummary_format_numeric_latex" = "plain")
modelsummary(list("DV: attrited [0;1]" = differential_attrition_check),
             stars = c('*' = .1, '**' = .05, '***' = .01),
             output = "latex",
             title = "Differential attrition check (Study 2)"
)

# MAKE TABLE A7 ----

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1)))

main_basic <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                        fixed_effects = as.factor(voivodeship),
                        data = temp)
main_interaction <- lm_robust(formula = outcome ~ exp_condition*popis + experiment_first,
                              fixed_effects = as.factor(voivodeship),
                              data = temp)
main_triple_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSparty_id_z + experiment_first,
                                     fixed_effects = as.factor(voivodeship),
                                     data = temp)

modelsummary(list(main_basic, main_interaction, main_triple_interaction),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A8 ----

# Logit model

# recode outcome
results <- results1 %>% 
  filter(outcome != 99) %>%
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>%  
  mutate(outcome_supports = ifelse(outcome > 5, 1, 0))

temp <- results %>% 
  filter(popis == "PO",
         !is.na(GSparty_id_z))

modelPO <- glm(outcome_supports ~ exp_condition*GSparty_id_z + experiment_first + as.factor(voivodeship), data = temp, family = binomial(link=logit))

temp <- results %>% 
  filter(popis == "PiS",
         !is.na(GSparty_id_z))

modelPiS <- glm(outcome_supports ~ exp_condition*GSparty_id_z + experiment_first + as.factor(voivodeship), data = temp, family = binomial(link=logit))

modelsummary(list(modelPO, modelPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A9 ----

# PO supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A10 ----

temp <- results2 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3)

main_basic <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                        fixed_effects = as.factor(voivodeship),
                        data = temp)
main_interaction <- lm_robust(formula = outcome ~ exp_condition*popis + experiment_first,
                              fixed_effects = as.factor(voivodeship),
                              data = temp)
main_triple_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSparty_id_z + experiment_first,
                                     fixed_effects = as.factor(voivodeship),
                                     data = temp)

modelsummary(list(main_basic, main_interaction, main_triple_interaction),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A11 ----

load(file = "./01 data/02 generated data/study2/02results_fullsample_clean.Rda")
results2 <- results %>%
  filter(outcome != 99) %>%
  filter(manipulation_check == 3)

# recode outcome
results <- results2 %>% 
  mutate(outcome_supports = ifelse(outcome > 5, 1, 0))

temp <- results %>% 
  filter(popis == "PO",
         !is.na(GSparty_id_z))

modelPO <- glm(outcome_supports ~ exp_condition*GSparty_id_z + experiment_first + as.factor(voivodeship), data = temp, family = binomial(link=logit))

temp <- results %>% 
  filter(popis == "PiS",
         !is.na(GSparty_id_z))

modelPiS <- glm(outcome_supports ~ exp_condition*GSparty_id_z + experiment_first + as.factor(voivodeship), data = temp, family = binomial(link=logit))


modelsummary(list(modelPO, modelPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A12 ----

# PO supporters only 

temp <- results2 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results2 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A13 ----

results1 <- results1 %>% 
  mutate(PiS_or_PO_and_party_id = PiS_or_PO,
         PiS_or_PO_and_party_id = ifelse(is.na(PiS_or_PO_and_party_id) & party_id == 3, 1, PiS_or_PO_and_party_id),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 1, "PiS", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 2, "PO", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 999, NA, as.character(PiS_or_PO_and_party_id)))


temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(PiS_or_PO_and_party_id == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(PiS_or_PO_and_party_id == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A14 ----

# PO supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(forced_POPiS_choice == 0) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(forced_POPiS_choice == 0) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A15 ----

# Study 1

# PO supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first + LR,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first + LR,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first + LR,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first + LR,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A16 ----

load(file = "./01 data/02 generated data/study1/01results_fullsample_clean.Rda")

temp <- results %>% 
  filter(outcome != "99")

basic <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                   fixed_effects = as.factor(voivodeship),
                   data = temp)
interaction <- lm_robust(formula = outcome ~ exp_condition*popis + experiment_first,
                         fixed_effects = as.factor(voivodeship),
                         data = temp)
triple_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSparty_id_z + experiment_first,
                                fixed_effects = as.factor(voivodeship),
                                data = temp)

modelsummary(list(basic, interaction, triple_interaction),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A17 ----

# PO supporters only

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A18 ----

load(file = "./01 data/02 generated data/study1/01results_fullsample_clean.Rda")
results1 <- results

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1)))

basic <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                   data = temp)
interaction <- lm_robust(formula = outcome ~ exp_condition*popis + experiment_first,
                         data = temp)
triple_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSparty_id_z + experiment_first,
                                data = temp)

modelsummary(list(basic, interaction, triple_interaction),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A19 ----

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           data = temp)

# PiS supporters only

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1))) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A20 ----

load(file = "./01 data/02 generated data/study2/02results_fullsample_clean.Rda")
results2 <- results %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3)
results2 <- results2 %>% 
  mutate(PiS_or_PO_and_party_id = PiS_or_PO,
         PiS_or_PO_and_party_id = ifelse(is.na(PiS_or_PO_and_party_id) & party_id == 3, 1, PiS_or_PO_and_party_id),
         PiS_or_PO_and_party_id = ifelse(is.na(PiS_or_PO_and_party_id) & party_id == 15, 2, PiS_or_PO_and_party_id),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 1, "PiS", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 2, "PO", as.character(PiS_or_PO_and_party_id)),
         PiS_or_PO_and_party_id = ifelse(PiS_or_PO_and_party_id == 999, NA, as.character(PiS_or_PO_and_party_id)))


# PO supporters only 

temp <- results2 %>% 
  filter(PiS_or_PO_and_party_id == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results2 %>%
  filter(PiS_or_PO_and_party_id == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A21 ----

# PO supporters only 

temp <- results2 %>%
  filter(forced_POPiS_choice == 0) %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results2 %>%
  filter(forced_POPiS_choice == 0) %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A22 ----

load(file = "./01 data/02 generated data/study2/02results_fullsample_clean.Rda")
temp <- results %>% 
  filter(outcome != "99")

basic <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                   fixed_effects = as.factor(voivodeship),
                   data = temp)
interaction <- lm_robust(formula = outcome ~ exp_condition*popis + experiment_first,
                         fixed_effects = as.factor(voivodeship),
                         data = temp)
triple_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSparty_id_z + experiment_first,
                                fixed_effects = as.factor(voivodeship),
                                data = temp)

modelsummary(list(basic, interaction, triple_interaction),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A23 ----

# PO supporters only

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     fixed_effects = as.factor(voivodeship),
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           fixed_effects = as.factor(voivodeship),
                           data = temp)

# PiS supporters only

temp <- results %>% 
  filter(outcome != "99") %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      fixed_effects = as.factor(voivodeship),
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            fixed_effects = as.factor(voivodeship),
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A24 ----


basic <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                   data = results2)
interaction <- lm_robust(formula = outcome ~ exp_condition*popis + experiment_first,
                         data = results2)
triple_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSparty_id_z + experiment_first,
                                data = results2)

modelsummary(list(basic, interaction, triple_interaction),
             stars = c('*' = .1, '**' = .05, '***' = .01))

# MAKE TABLE A25 ----

# PO supporters only

temp <- results2 %>% 
  filter(popis == "PO")

basicPO <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                     data = temp)
interactionPO <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                           data = temp)

# PiS supporters only

temp <- results2 %>% 
  filter(popis == "PiS")

basicPiS <- lm_robust(formula = outcome ~ exp_condition + experiment_first,
                      data = temp)
interactionPiS <- lm_robust(formula = outcome ~ exp_condition*GSparty_id_z + experiment_first,
                            data = temp)

modelsummary(list(basicPO, interactionPO, basicPiS, interactionPiS),
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A26 ----

temp <- results1 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check1 == 3 | (is.na(manipulation_check1)))

negativepart_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSnegative_partisan_z + experiment_first,
                                      fixed_effects = as.factor(voivodeship),
                                      data = temp)

modelsummary(negativepart_interaction,
             stars = c('*' = .1, '**' = .05, '***' = .01))


# MAKE TABLE A27 ----

temp <- results2 %>% 
  filter(outcome != "99") %>% 
  filter(manipulation_check == 3)

negativepart_interaction <- lm_robust(formula = outcome ~ exp_condition*popis*GSnegative_partisan_z + experiment_first,
                                      fixed_effects = as.factor(voivodeship),
                                      data = temp)

modelsummary(negativepart_interaction,
             stars = c('*' = .1, '**' = .05, '***' = .01))



